package com.misakyanls.examples.random;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

public class RandomList {

	public List<Integer> createListWithUniqueSortedValues(int howMany, int highValue) {
		List<Integer> list = new ArrayList<Integer>();

		int[] array = new int[highValue];
		for (int i = 0; i < highValue; i++) {
			array[i] = i + 1;
		}

		Random generator = new Random();
		for (int i = 0; i < howMany; i++) {
			int index = generator.nextInt(highValue);
			list.add(i, array[index]);
			array[index] = array[highValue - 1];
			highValue--;
		}

		Collections.sort(list);
		return list;
	}

	public List<Integer> rotateList(List<Integer> list) {
		List<Integer> temporary = new LinkedList<Integer>(list);
		List<Integer> result = new ArrayList<Integer>();
		int size = temporary.size();
		Random generator = new Random();
		
		for (int i = 0; i < list.size(); i++) {
			int index = generator.nextInt(size);
			result.add(i, temporary.get(index));
			temporary.set(index, temporary.get(--size));
			
		}
		
		return result;
	}

	public static void main(String[] args) {

		// System.out.println(createListWithUniqueRandomValues(10, 36));
	}
}
